<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>
			兄弟海鲜管理系统
		</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="./css/x-admin.css" media="all">

		<link href="css/xtiper.css" type="text/css" rel="stylesheet" />
		<script src="js/xtiper.min.js" type="text/javascript"></script>

	</head>

	<body onload="findall()">
		<div class="x-nav">
			<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>
		<div class="x-body">
			<div style="margin-bottom: 15px;">
				<label class="layui-form-label">查询商品</label>
				<div class="layui-input-inline">
					<input type="text" id="speciesName" name="speciesName" placeholder="商品名称" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-input-inline" style="width:80px">
					<button class="layui-btn" onclick="search()"><i class="layui-icon">&#xe615;</i></button>
				</div>
			</div>
			<xblock>
				<button class="layui-btn layui-btn-danger" onclick="batchup()">
            		批量上架</button>
				<button class="layui-btn layui-btn-danger" onclick="batchdown()">
            		批量下架</button>
				<button class="layui-btn" onclick="insertgoods()">
            		<i class="layui-icon">&#xe608;</i>添加</button>
				<span class="x-right" style="line-height:40px">已上架商品共：<button id="total" name="total" title="查看上架商品" onclick="show()"></button> 件</span>
			</xblock>
			<table class="layui-table">
				<thead>
					<tr>
						<th>
						</th>
						<th>
							ID
						</th>
						<th>
							商品名称
						</th>
						<th>
							商品样式
						</th>

						<th>
							商品类型
						</th>
						<th>
							商品介绍
						</th>
						<th>
							商品价格
						</th>
						<th>
							商品单位
						</th>
						<th>
							剩余商品数量
						</th>
						<th>
							状态
						</th>
						<th>
							操作
						</th>
					</tr>
				</thead>
				<tbody id="specieslist">
				</tbody>
			</table>
			
            <div id="page" ></div>
		</div>
		<script src="./lib/layui/layui.js" charset="utf-8"></script>
		<script src="./js/x-layui.js" charset="utf-8"></script>
		<script type="text/javascript">
			function findall(pageNmber) {
				var url = 'http://127.0.0.1:8080/species/findPage?page=1&size=10';
				$.ajax({
					type: "get", //post方式传输，比get更加密安全
					url: url, //请求地址
					contentType: "application/json;charsetset=UTF-8",
					success: function(data) {
						var a = 1;
						var sum = 0;
						var msg = "";
						for(var i = 0; i < data.list.length; i++) {
							msg += '<tr> <td>';
							msg += '<input type=\"checkbox\" value=\"' + data.list[i].speciesId + '\" id=\"speciesId\" name=\"speciesId\"></td> ';
							msg += '<td>' + a + '</td> ';
							msg += '<td>' + data.list[i].speciesName + '</td>';
							msg += '<td><img  src=\"images/speciesImg/' + data.list[i].speciesImg + '\" width=\"100\" ></td>';
							msg += ' <td >' + data.list[i].types.typeName + '</td>';
							msg += ' <td style=\"width: 100px;text-overflow:ellipsis;\">' + data.list[i].speciesIntroduce + '</td>';
							msg += ' <td >' + data.list[i].speciesPrice + '</td>';
							msg += ' <td >' + data.list[i].unit.unitName + '</td>';
							msg += ' <td >' + data.list[i].speciesTotal + '</td>';
							if(data.list[i].speciesState == '已下架') {
								msg += '<td><span class=\"layui-btn layui-btn-disabled layui-btn-mini\"> ' + data.list[i].speciesState + '</span></td>';
							} else {
								msg += '<td><span class=\"layui-btn layui-btn-normal layui-btn-mini\"> ' + data.list[i].speciesState + '</span></td>';
							}
							msg += '<td class=\"td-manage\"> ';
							msg += ' <a title=\"上架商品\" href=\"javascript:;\" class=\"ml-5\" style=\"text-decoration:none\" onclick=\"updateState1(' + data.list[i].speciesId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/上架.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += ' <a title=\"下架商品\" href=\"javascript:;\" class=\"ml-5\" style=\"text-decoration:none\" onclick=\"updateState(' + data.list[i].speciesId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/下架.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += ' <a title=\"修改商品\" href=\"javascript:;\" class=\"ml-5\" style=\"text-decoration:none\" onclick=\"updatespecies(' + data.list[i].speciesId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/修改.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += '<a class=\"xbutton\" title=\"删除商品\" onclick=\"deletebyid(' + data.list[i].speciesId + ')\" >';
							msg += '<i><img src=\"images/删除.png\" style=\"width: 25;\" height=\"25\"></i>';
							msg += '</a> </td> </tr>';
							if(data.list[i].speciesState == '已上架') {
								sum++;
							}
							a++;
						}
						$("#specieslist").html(msg);
						$("#total").text(sum);
						
					},
					error: function() {
						alert("失败");
					}
				})
			}
		</script>
		<script type="text/javascript">
			function findall2(pageNmber) {
				var url = 'http://127.0.0.1:8080/species/findPage?page='+pageNmber+'&size=10';
				$.ajax({
					type: "get", //post方式传输，比get更加密安全
					url: url, //请求地址
					contentType: "application/json;charsetset=UTF-8",
					success: function(data) {
						var a = 1;
						var sum = 0;
						var msg = "";
						for(var i = 0; i < data.list.length; i++) {
							msg += '<tr> <td>';
							msg += '<input type=\"checkbox\" value=\"' + data.list[i].speciesId + '\" id=\"speciesId\" name=\"speciesId\"></td> ';
							msg += '<td>' + a + '</td> ';
							msg += '<td>' + data.list[i].speciesName + '</td>';
							msg += '<td><img  src=\"images/speciesImg/' + data.list[i].speciesImg + '\" width=\"100\" ></td>';
							msg += ' <td >' + data.list[i].types.typeName + '</td>';
							msg += ' <td style=\"width: 100px;text-overflow:ellipsis;\">' + data.list[i].speciesIntroduce + '</td>';
							msg += ' <td >' + data.list[i].speciesPrice + '</td>';
							msg += ' <td >' + data.list[i].unit.unitName + '</td>';
							msg += ' <td >' + data.list[i].speciesTotal + '</td>';
							if(data.list[i].speciesState == '已下架') {
								msg += '<td><span class=\"layui-btn layui-btn-disabled layui-btn-mini\"> ' + data.list[i].speciesState + '</span></td>';
							} else {
								msg += '<td><span class=\"layui-btn layui-btn-normal layui-btn-mini\"> ' + data.list[i].speciesState + '</span></td>';
							}
							msg += '<td class=\"td-manage\"> ';
							msg += ' <a title=\"上架商品\" href=\"javascript:;\" class=\"ml-5\" style=\"text-decoration:none\" onclick=\"updateState1(' + data.list[i].speciesId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/上架.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += ' <a title=\"下架商品\" href=\"javascript:;\" class=\"ml-5\" style=\"text-decoration:none\" onclick=\"updateState(' + data.list[i].speciesId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/下架.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += ' <a title=\"修改商品\" href=\"javascript:;\" class=\"ml-5\" style=\"text-decoration:none\" onclick=\"updatespecies(' + data.list[i].speciesId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/修改.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += '<a class=\"xbutton\" title=\"删除商品\" onclick=\"deletebyid(' + data.list[i].speciesId + ')\" >';
							msg += '<i><img src=\"images/删除.png\" style=\"width: 25;\" height=\"25\"></i>';
							msg += '</a> </td> </tr>';
							if(data.list[i].speciesState == '已上架') {
								sum++;
							}
							a++;
						}
						$("#specieslist").html(msg);
						$("#total").text(sum);
						
					},
					error: function() {
						alert("失败");
					}
				})
			}
		</script>
		<script src="js/jquery.min.js"></script>

		<script type="text/javascript">
			function search() {
				var speciesName = $("#speciesName").val();
				var url = 'http://127.0.0.1:8080/species/findPage?page=1&size=10';
				var settings = {
					"url": url,
					"method": "POST",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					},
					"data": JSON.stringify({
						"name": speciesName
					}),
				};
				$.ajax(settings).done(function(response) {
					if(response != "") {
						$('#specieslist').empty();
						var a = 1;
						var sum = 0;
						var msg = "";
						for(var i = 0; i < response.list.length; i++) {
							msg += '<tr> <td>';
							msg += '<input type=\"checkbox\" value=\"' + response.list[i].speciesId + '\" id=\"speciesId\" name=\"speciesId\"></td> ';
							msg += '<td>' + a + '</td> ';
							msg += '<td>' + response.list[i].speciesName + '</td>';
							msg += '<td><img  src=\"images/speciesImg/' + response.list[i].speciesImg + '\" width=\"100\" ></td>';
							msg += ' <td >' + response.list[i].types.typeName + '</td>';
							msg += ' <td style=\"width: 100px;text-overflow:ellipsis;\"> ' + response.list[i].speciesIntroduce + '</td>';
							msg += ' <td >' + response.list[i].speciesPrice + '</td>';
							msg += ' <td >' + response.list[i].unit.unitName + '</td>';
							msg += ' <td >' + response.list[i].speciesTotal + '</td>';
							if(response.list[i].speciesState == '已下架') {
								msg += '<td><span class=\"layui-btn layui-btn-disabled layui-btn-mini\"> ' + response.list[i].speciesState + '</span></td>';
							} else {
								msg += '<td><span class=\"layui-btn layui-btn-normal layui-btn-mini\"> ' + response.list[i].speciesState + '</span></td>';
							}
							msg += '<td class=\"td-manage\"> ';
							msg += ' <a title=\"上架商品\" href=\"javascript:;\" class=\"ml-5\" style=\"text-decoration:none\" onclick=\"updateState1(' + response.list[i].speciesId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/上架.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += ' <a title=\"下架商品\" href=\"javascript:;\" class=\"ml-5\" style=\"text-decoration:none\" onclick=\"updateState(' + data.list[i].speciesId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/下架.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += ' <a title=\"修改商品\" href=\"javascript:;\" class=\"ml-5\" style=\"text-decoration:none\" onclick=\"updatespecies(' + response.list[i].speciesId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/修改.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += '<a class=\"xbutton\" title=\"删除商品\" onclick=\"deletebyid(' + response.list[i].speciesId + ')\" >';
							msg += '<i><img src=\"images/删除.png\" style=\"width: 25;\" height=\"25\"></i>';
							msg += '</a> </td> </tr>';
							if(response.list[i].speciesState == '已上架') {
								sum++;
							}
							a++;
						}
						$("#specieslist").html(msg);
						$("#total").text(sum);
					} else {
						xtip.msg("失败");
					}
				})
			}
		</script>
		<script type="text/javascript">
			layui.use(['layer','laypage'], function() {
				layer = layui.layer; //弹出层
				 laypage = layui.laypage;//分页
				 laypage({
                cont: 'page'
                ,pages: 100
                ,first: 1
                ,last: 100
                ,prev: '<em><</em>'
                ,next: '<em>></em>',
                jump: function(obj){
                	var pageNmber=obj.curr;
                	findall2(pageNmber);
                }
              }); 
			});

			function updatespecies(speciesId) {
				var url = 'http://127.0.0.1:8080/species/findspecies?speciesId=' + speciesId;
				$.ajax({
					type: "post", //post方式传输，比get更加密安全
					url: url, //请求地址
					success: function(data) {
						if(data.speciesState == '已上架') {
							xtip.msg('请先下架再修改信息');
						} else {
							sessionStorage.setItem("speciesId", JSON.stringify(data.speciesId));
							sessionStorage.setItem("speciesName", JSON.stringify(data.speciesName));
							sessionStorage.setItem("speciesPrice", JSON.stringify(data.speciesPrice));
							sessionStorage.setItem("speciesIntroduce", JSON.stringify(data.speciesIntroduce));
							sessionStorage.setItem("typeName", JSON.stringify(data.types.typeName));
							sessionStorage.setItem("unitName", JSON.stringify(data.unit.unitName));
							sessionStorage.setItem("speciesImg", JSON.stringify(data.speciesImg));
							sessionStorage.setItem("speciesTotal", JSON.stringify(data.speciesTotal));
							x_admin_show("用户编辑", './species-edit.html', '600', '500');
						}

					},
					error: function() {
						xtip.msg("失败");
					}
				})
			}
		</script>

		<script type="text/javascript">
			function batchup() {
				var arr = [];
				$("input:checkbox[name='speciesId']:checked").each(function() {
					arr.push($(this).val());
				});
				var settings = {
					"url": "http://127.0.0.1:8080/species/batch?speciesState=已上架",
					"method": "POST",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					},
					"data": JSON.stringify(arr),
				};

				$.ajax(settings).done(function(response) {
					xtip.msg("批量上架成功，确认后刷新");
					setTimeout(function() {
						location.href = "./species-list.html";
					}, 1000);
				});
			}
		</script>
		<script type="text/javascript">
			function batchdown() {
				var arr = [];
				$("input:checkbox[name='speciesId']:checked").each(function() {
					arr.push($(this).val());
				});
				var settings = {
					"url": "http://127.0.0.1:8080/species/batch?speciesState=已下架",
					"method": "POST",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					},
					"data": JSON.stringify(arr),
				};

				$.ajax(settings).done(function(response) {
					xtip.msg("批量下架成功，确认后刷新");
					setTimeout(function() {
						location.href = "./species-list.html";
					}, 1000);
				});
			}
		</script>

		<script type="text/javascript">
			function deletebyid(speciesId) {
				xtip.confirm('确认删除吗？', function() {
					var url = 'http://127.0.0.1:8080/species/delete?speciesId=' + speciesId;
					var settings = {
						"url": url,
						"method": "GET",
						"timeout": 0,
						"headers": {
							"Content-Type": "application/json"
						},
					};
					$.ajax(settings).done(function(response) {
						xtip.msg('删除成功！');
						setTimeout(function() {
							location.href = "./species-list.html";
						}, 1000);

					});
				});
			}
		</script>
		<script type="text/javascript">
			function insertgoods() {
				setTimeout(function() {
					location.href = "./species-add.html";
				}, 1000);
			}

			function show() {
				setTimeout(function() {
					location.href = "./species-list-show.html";
				}, 1000);
			}

			function updateState1(speciesId) {
				var str = 'http://127.0.0.1:8080/species/updateState1?speciesId=' + speciesId;
				var settings = {
					"url": str,
					"method": "GET",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					}
				};
				$.ajax(settings).done(function(response) {
					xtip.msg("上架成功");
					setTimeout(function() {
						location.href = "./species-list.html";
					}, 1000);
				});
			}

			function updateState(speciesId) {
				var str = 'http://127.0.0.1:8080/species/updateState?speciesId=' + speciesId;
				var settings = {
					"url": str,
					"method": "GET",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					}
				};
				$.ajax(settings).done(function(response) {
					xtip.msg("下架成功");
					setTimeout(function() {
						location.href = "./species-list.html";
					}, 1000);
				});
			}
			
		</script>
	</body>

</html>